Harden Java runtime compiler caching, I/O safety, and documentation/agent guidance - #166
Draft
peter-lawrey wants to merge 14 commits into
Draft
Harden Java runtime compiler caching, I/O safety, and documentation/agent guidance#166peter-lawrey wants to merge 14 commits into
peter-lawrey wants to merge 14 commits into
Conversation
…rmance improvements
…entation guidelines
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Refresh on 12 September 2026
Merged develop
320054faf7c8474513e952bec1096d87f7312884into the existing branch with normal forward commits. Updated head:9c49755ff3fbe27f5ec106de7b134be701a81138. Both develop320054faf7c8474513e952bec1096d87f7312884and the declared parent are ancestors of this head; both missing-commit counts are zero.Retained current parent and third-party BOM coordinates. Full clean verify passed on Java 21: 44 reported tests, none skipped. Selected documentation rendered.
Compiler cache/reset/filesystem behavior remains distinct from documentation and quality policy; generated-class consumers and supported-JVM CI remain review gates.
Local runs used Linux x86-64 and OpenJDK 21.0.12 unless Java 8 is explicitly stated (8u502). Reported test counts include skips. Commands requested zero Surefire reruns. Draft status and declared target are retained.
Earlier implementation/review notes follow. Earlier validation and performance claims apply only to their stated revisions and are superseded by the current receipt above where they differ.
This PR improves the Java Runtime Compiler’s cached compiler lifecycle, file I/O robustness, and documentation/agent guidance, while maintaining compatibility with existing callers.
Functional changes
Thread-safe compiler and file-manager initialisation
CompilerUtilsnow treatss_compilerands_standardJavaFileManagerasvolatileand introducescurrentCompiler()plus a synchronisedreset():JavaCompiler.s_standardJavaFileManagerwhenever the compiler is reset, preventing a file manager from being tied to a stale compiler instance.CachedCompiler.compileFromJava(...)andloadFromJava(...)now always usecurrentCompiler():s_compileris already initialised.StandardJavaFileManager.These changes reduce the risk of races and
NullPointerExceptions when the cached compiler is used concurrently or after a reset.Safer file I/O and backup handling
CompilerUtils.readBytes(...)now usesFiles.newInputStream(file.toPath())in a try-with-resources block:nullon missing files, throws on I/O errors) but closes streams reliably.CompilerUtils.writeBytes(...):StandardCharsets.UTF_8for logging decoded content..bakwhen necessary, and logs when rename/delete/restore operations fail.Net effect: same successful-path behaviour, but more predictable error handling and better diagnostics when I/O fails.
Cached compilation behaviour
compileFromJava(...)now reuses a lazily-initialisedStandardJavaFileManagervia a local variable and double-checked initialisation under aCompilerUtils.classlock.fileManager.getAllBuffers()directly rather than via a temporary local, with no change to the returned data.loadFromJava(...)continues to createMyJavaFileManagerinstances per class loader, but now uses thecurrentCompiler()helper for consistency with the rest of the codebase.Dependency alignment
net.openhft:third-party-bomfrom3.27ea5to3.27ea7to align this module with the latest shared dependency set used across Chronicle projects.Test harness behaviour
FooBarTeenow derives theFoo’s integer argument fromname.length()instead of a hard-coded literal.ClassLoaderinstances viaAccessController.doPrivileged(...), ensuring they continue to work correctly under a security manager / restricted environments.RuntimeCompileTest.outOfBoundsadds a stricter type assertion for the thrownIllegalArgumentException, clarifying expected behaviour.Non-functional changes
Language, encoding, and agent guidance (
AGENTS.md)Updated language/encoding policy from “ASCII-7 only” to ISO-8859-1 (code points 0–255), still discouraging smart quotes, non-breaking spaces, and accented characters.
Added explicit reference to the University of Oxford style guide for British English spelling.
Documented practical tools for catching stray non-ASCII characters (e.g.
iconvand IDE inspections).Clarified Javadoc and inline comment guidance with concrete “good vs bad” examples, emphasising comments that add behavioural insight instead of restating the obvious.
Extended build guidance:
mvn -q clean verifyfrom a clean checkout.-P quality,-P sonar, and module-scoped-P module-quality.Added a “When to open a PR” section to align contributor workflow (green build, focused diffs, linked issues/decisions).
Introduced a security checklist for reviewers:
Requirements and decision-log structure & traceability
Moved the project requirements from
src/main/adoctosrc/main/docsand wiredAGENTS.mdlinks to the new locations.project-requirements.adoc::sectnums:and added:source-highlighter: rouge.<=instead of typographic symbols).RC-FN-002/RC-RISK-026, JRC-NF-P-006 →RC-NF-P-006, JRC-TEST-014 →RC-TEST-002).decision-log.adoc:Replaced the minimal header with a fully-structured AsciiDoc document (title,
:toc:,:sectnums:,:lang: en-GB,:source-highlighter: rouge).Added a Decision Index and expanded the log with new entries:
RC-FN-002– cached compiler API and custom class loaders.RC-NF-P-006– performance & metaspace budget for cached compilation.RC-RISK-026– safe handling of debug artefact directories.Existing decisions (
RC-FN-001,RC-TEST-002) were updated to reference the relocated requirements paths.Improved decision-record template and AsciiDoc conventions in
AGENTS.md:Term ::notation (Date, Context, Decision Statement, Alternatives, Rationale, Impact & Consequences, Notes/Links).:sectnums:usage and discouraging manual numeric prefixes in headings.Code quality, style, and logging
Switched to
StandardCharsets.UTF_8instead ofCharset.forName("UTF-8")and removed legacyUnsupportedEncodingExceptionbranches.Tightened logging in
MyJavaFileManagerto use SLF4J placeholders ([class={}]) rather than string concatenation.Cleaned up minor style issues:
public int get()→int get()inMyIntSupplier).assertTrue(!condition)withassertFalse(condition)and==withassertSamewhere identity is being asserted.StandardCharsets.UTF_8usage when constructingPrintStreams and decoding streams in tests, improving cross-platform determinism.Updated various tests to use more precise messages and to avoid anonymous
Callableimports via fully-qualified types, aligning with Checkstyle/SpotBugs expectations.Overall, this PR strengthens the cached compiler’s threading and I/O story, aligns requirements and decisions with a traceable Nine-Box taxonomy, and gives AI agents and human contributors clearer, security-aware guidance on how to work within the Java Runtime Compiler module.